package com.ict.txmsv2.services;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ict.txmsv2.mapper.UserFaceInfoMapper;
import com.ict.txmsv2.model.FaceUserInfo;
import com.ict.txmsv2.model.UserFaceInfo;

import java.io.File;
import java.util.List;


@Service
public class UserFaceInfoServiceImpl implements UserFaceInfoService {


    @Autowired
    private UserFaceInfoMapper userFaceInfoMapper;

    @Override
    public void insertSelective(UserFaceInfo userFaceInfo) {
        userFaceInfoMapper.insertSelective(userFaceInfo);
    }

    @Override
    public int getMaxId() {
        return userFaceInfoMapper.getMaxId();
    }

    @Override
    public int delUserFace(Integer id) {
        UserFaceInfo userFaceInfo = userFaceInfoMapper.getUserFaceInfo(id);
        if (StringUtils.isNotEmpty(userFaceInfo.getFpath()))
        {
            new File(userFaceInfo.getFpath()).delete();
        }
        return userFaceInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int delManyUserFace(Integer[] ids) {
        int i=0;
        for (Integer id : ids) {
            i += delUserFace(id);
        }
        return i;
    }

    @Override
    public int updateByPrimaryKeySelective(UserFaceInfo userFaceInfo) {
        return userFaceInfoMapper.updateByPrimaryKeySelective(userFaceInfo);
    }

    @Override
    public List<FaceUserInfo> getUserFaceInfoByGroupId(Integer groupId) {
        return userFaceInfoMapper.getUserFaceInfoByGroupId(groupId);
    }

    @Override
    public List<UserFaceInfo> getUfiByGroupId(Integer groupId) {
        return userFaceInfoMapper.getUfiByGroupId(groupId);
    }

    @Override
    public UserFaceInfo getUserFaceInfo(Integer faceId) {
        return userFaceInfoMapper.getUserFaceInfo(faceId);
    }

    @Override
    public UserFaceInfo getUserFaceInfoByUserId(Integer userId) {
        return userFaceInfoMapper.getUserFaceInfoByUserId(userId);
    }
}
